(function() {
	jQuery.extend({
		AjaxAuthFilter : {
			userId:undefined,
			cover:undefined,
			 
			logincallback:undefined,
		    diffcallback:undefined,
		    samecallback:undefined,
			
			init:function(userId,callback){
				this.userId = userId;
				var type = typeof(callback);
				if(type=="function"){
					if(callback){
						this.samecallback = callback;
					}
				}else if(type == "object"){
					if(callback.logined){
						this.logincallback = callback.logined;
					}
					if(callback.diff){
						this.diffcallback = callback.diff;
					}
					if(callback.same){
						this.samecallback = callback.same;
					}
				}
			},
			checkSession : function(logurl,data,callback) {
				var boo = data == "SESSION_TIMEOUT";
				if (boo) {
					this.removeCover();
					this.cover = $("<div class='ajax-login'></div>");
					var back = $("<div class='ajax-login-back'></div>");
					var context = $("<div class='ajax-login-context'>");
					
					var title = $("<div class='ajax-login-title' ><div class='left'>登录超时</div><div class='right'> <a href='javascript:$.AjaxAuthFilter.removeCover()'>关闭</a></div><div class='clear'></div> </div>");
					var iframe = $("<iframe src='"+logurl+"' frameborder='0' marginwidth='0' marginheight='0' scrolling='no'  class='ajax-login-iframe'>");
					context.append(title);
					context.append(iframe);
					this.cover.append(back);
					this.cover.append(context);
					$("body") .append(this.cover);
					this.init(this.userId, callback);
				}
				return !boo;
			},
			cleckOver:function(user){
				if(user){
					if(typeof(this.logincallback)=="function"){
						this.logincallback(user);
					}
					if(this.userId!=undefined){
						if( this.userId!=user.id){
							if(typeof(this.diffcallback)=="function"){
								this.diffcallback(user);
							}
							
						}else{
							if(typeof(this.samecallback)=="function"){
								this.samecallback(user);
							}
						}
					}
					this.userId = user.id;
					this.removeCover();
				}
				 
			},
			removeCover:function(){
				if(this.cover&&this.cover.remove){
					this.cover.find("iframe").attr('src','');
					this.cover.remove();
					this.cover = undefined;
				}
			}
			
		}
	});

})(jQuery);
